package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TbNode;
import com.ruoyi.system.service.ITbNodeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 点位Controller
 * 
 * @author ruoyi
 * @date 2023-06-14
 */
@RestController
@RequestMapping("/system/node")
public class TbNodeController extends BaseController
{
    @Autowired
    private ITbNodeService tbNodeService;

    /**
     * 查询点位列表
     */
    @PreAuthorize("@ss.hasPermi('system:node:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbNode tbNode)
    {
        startPage();
        List<TbNode> list = tbNodeService.selectTbNodeList(tbNode);
        return getDataTable(list);
    }

    /**
     * 导出点位列表
     */
    @PreAuthorize("@ss.hasPermi('system:node:export')")
    @Log(title = "点位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbNode tbNode)
    {
        List<TbNode> list = tbNodeService.selectTbNodeList(tbNode);
        ExcelUtil<TbNode> util = new ExcelUtil<TbNode>(TbNode.class);
        util.exportExcel(response, list, "点位数据");
    }

    /**
     * 获取点位详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:node:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbNodeService.selectTbNodeById(id));
    }

    /**
     * 新增点位
     */
    @PreAuthorize("@ss.hasPermi('system:node:add')")
    @Log(title = "点位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbNode tbNode)
    {
        return toAjax(tbNodeService.insertTbNode(tbNode));
    }

    /**
     * 修改点位
     */
    @PreAuthorize("@ss.hasPermi('system:node:edit')")
    @Log(title = "点位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbNode tbNode)
    {
        return toAjax(tbNodeService.updateTbNode(tbNode));
    }

    /**
     * 删除点位
     */
    @PreAuthorize("@ss.hasPermi('system:node:remove')")
    @Log(title = "点位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbNodeService.deleteTbNodeByIds(ids));
    }
} 